class_name ComboIndicator
extends Label


## 连击超时时间（秒），超过超时时间后连击数清零
@export var duration_combo_timeout: float = 2.0

@warning_ignore("unused_signal")
signal combo_reset(points: int)


var time_register_hit: float = 0.0
var combo_counter: int = 0


func _init():
	ComboManager.register_hit.connect(on_register_hit)


func _ready():
	combo_counter = 0
	display_combo()


func _process(delta: float):
	if time_register_hit < 0.0 and combo_counter != 0:
		reset_combo()
		return
	time_register_hit -= delta


func on_register_hit():
	time_register_hit = duration_combo_timeout
	combo_counter += 1
	display_combo()


func display_combo():
	if combo_counter == 0:
		text = ""
		visible = false
	else:
		text = "x" + str(combo_counter)
		visible = true


func reset_combo():
	combo_reset.emit(combo_counter)
	time_register_hit = 0.0
	combo_counter = 0
	display_combo()
